<?

//	*********************************
//	SbSE DB metadata delete component
//	v1.1.0 / 2012.04.27
//	*********************************

require_once E.'_lib/_db.php';

class KILLMETA {

	var $where;		// WHERE
	var $replacement;	// replacement

	var $res;

	var $err = array (
		0 => 'success',
		1 => 'empty result',
		255 => 'not initialized'
	);
	
	function KILLMETA() {

		$this->tables = '';
		$this->where = defined('USE_ADODB_OCI') ? '1=1' : 1;

		$this->res = 255;
	}

	function init( $where = '' ) {

		$this->table = tb('data');
		$this->xtable = tb('xdata');
	
		if ($where)
			$this->where = str_replace(';', '', $where);
		else
			return 0;	// NO DIRECT EMPTY TABLE ALLOWED


		$this->res = $this->fetch();

		return ! (bool) $this->res;
	}


	function fetch() {
		
		$sql1 = "DELETE FROM {$this->xtable} WHERE id IN (SELECT id FROM {$this->table} WHERE ({$this->where}))";
		$sql2 = "DELETE FROM {$this->table} WHERE ({$this->where})";

		if (defined('USE_ADODB')) {
			
			$GLOBALS['db']->Execute($sql1);
			$GLOBALS['db']->Execute($sql2);

		} else {

			$q = new SQL($sql1);
			$q->run();

			$q = new SQL($sql2);
			$q->run();
		}

		return 0;		// ok
	}
	

	function error() { return $this->err[$this->res]; }

}